<?php
/**
 * Created by 张彪.
 * User: 小马出行
 * Date: 2018/4/18
 * Time: 11:34
 */
namespace app\admin\inter_model;
use app\inter\model\InterBase;
use think\Model;
use think\Db;

class CarBanModel extends InterBase
{
    public function addBanci($data)
    {
        return Db::table('inter_car_banci')->insertGetId($data);
    }

    public function updateBanci($map,$data)
    {
        return Db::table('inter_car_banci')->where($map)->update($data);
    }

    public function getBanciList($map,$field='cb.*',$page=1,$limit=10,$config='')
    {
        $config = $config?:$this->config;

        return Db::connect($config)->name('car_banci cb')
            ->join('arean s','cb.start_address=s.id','LEFT')
            ->join('arean e','cb.end_address=e.id','LEFT')
            ->join('rail r1','r1.id=cb.start_rail_id','LEFT')
            ->join('rail r2','r2.id=cb.end_rail_id', 'LEFT')
            ->where($map)
            ->field($field)
            ->page($page,$limit)
            ->order('cb.id desc')->select();
    }

    public function searchBanci($map,$field='*',$config='')
    {
        return Db::table('inter_car_banci')->where($map)->field($field)->find();
    }

    public function deleteBanci($map)
    {
        return Db::table('inter_car_banci')->where($map)->delete();
    }

    public function getCarBanciGroup($map,$field='*',$group='')
    {
        if(empty($group)){
            return false;
        }
        return Db::table('inter_car_banci')->where($map)->field($field)->group($group)->select();
    }
}